#!/usr/bin/env python3
import re
import shutil
import sys

def main():
	shutil.copy(f'{sys.argv[1]}', f'{sys.argv[2]}')
	offset = int(sys.argv[3], 16)
	with open("linker.ld", 'r') as rf:
		linker = rf.read()
	linker = re.sub(r'\+ 0x\w+', f'+ 0x{offset:08X}', linker)
	with open("linker.ld", 'w') as wf:
		wf.write(linker)

if __name__ == "__main__":
	if sys.version_info < (3, 8):
		print("Python 3.8 or later is required.")
		sys.exit(1)
	else:
		main()